# encoding: UTF-8
 
class Admin::DownloadsController < ApplicationController
  
  before_filter :user_signed_in?
  
  def index
    @downloads = Download.all
    set_seo_meta '下载中心'
  end

  def new
    @dsort = Dsort.open_status
    set_seo_meta '增加下载文件'
  end
  
  def create
    @download = Download.new(params[:session])
    if @download.save!
      redirect_to downloads_path, notice: '新增成功!'
    else
      redirect_referrer_or_default default
    end  
  end

  def edit
    @dsort = Dsort.open_status
    @download = Download.find(params[:id]) 
    set_seo_meta '内容修改'
  end

  def update
    @download = Download.find(params[:id])
    if @download.update_attributes!(params[:session])
      redirect_to downloads_path, notice:'修改成功'
    else
      redirect_referrer_or_defautl default
    end
  end

  def destroy
    if Download.delete(params[:id])
      redirect_to downloads_path, notice:'删除成功'
    else
      redirect_referrer_or_default default
    end  
  end

end
